package leetcode.method.pointer;

public class Program167TwoSum {

    public Program167TwoSum() {
    }

    public int[] twoSum(int[] numbers, int target) {

        int left = 0;
        int right = numbers.length - 1;
//        int mid = (right - left) >> 1 + left;
        int[] res = new int[2];
        while (left < right) {
            if (numbers[left] + numbers[right] == target) {
                res[0] = left + 1;
                res[1] = right + 1;
                break;
            } else if (numbers[left] + numbers[right] < target) {
                left++;
            } else {
                right--;
            }
        }
        return res;
    }

    public static void main(String[] args) {
        Program167TwoSum obj = new Program167TwoSum();
        int[] numbers = {2,7,11,15};
        int[] ints = obj.twoSum(numbers, 9);
        System.out.println(ints[0]);
        System.out.println(ints[1]);
        int[] numbers1 = {2,3,4};
        int[] ints1 = obj.twoSum(numbers1, 6);
        System.out.println(ints1[0]);
        System.out.println(ints1[1]);
    }
}
